
<!DOCTYPE html>
<html lang="en" class="loading">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Springcloud学习笔记(四) - kyralo</title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate">
    <meta name="keywords" content="kyralo,"> 
    <meta name="description" content="三、Ribbon负载均衡1、概述基于Netflix ribbon实现的一套 ==客户端、负载均衡的工具==
重要功能是提供==客户端的软件负载均衡算法==，Ribbon客户端组件提供一系列的配置项如,"> 
    <meta name="author" content="kyralo"> 
    
    <link rel="icon" href="https://cdn.jsdelivr.net/gh/kyralo/cdn/ico/favicon.ico"> 
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kyralo/cdn@v1.0.2/css/diaspora.css">
    <!-- <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> -->
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({
              google_ad_client: "ca-pub-8691406134231910",
              enable_page_level_ads: true
         });
    </script>
    <!-- <script async custom-element="amp-auto-ads"
        src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js">
    </script> -->
</head>
</html>
<body class="loading">
    <span id="config-title" style="display:none">kyralo</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="icon-home image-icon" href="javascript:;" data-url="https://kyralo.github.io"></a>
    <!-- <div title="播放/暂停" class="icon-play"></div> -->
    <h3 class="subtitle">Springcloud学习笔记(四)</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">Springcloud学习笔记(四)</h1>
        <div class="stuff">
            <span>八月 17, 2019</span>
            
  <ul class="post-tags-list"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/Java/">Java</a></li><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/Springcloud/">Springcloud</a></li><li class="post-tags-list-item"><a class="post-tags-list-link" href="/tags/微服务/">微服务</a></li></ul>


        </div>
        <div class="content markdown">
            <h1 id="三、Ribbon负载均衡"><a href="#三、Ribbon负载均衡" class="headerlink" title="三、Ribbon负载均衡"></a>三、Ribbon负载均衡</h1><h2 id="1、概述"><a href="#1、概述" class="headerlink" title="1、概述"></a>1、概述</h2><p>基于Netflix ribbon实现的一套 ==客户端、负载均衡的工具==</p>
<p>重要功能是提供==客户端的软件负载均衡算法==，Ribbon客户端组件提供一系列的配置项如链接超时、重试等</p>
<p>官网资料：github：Netfix/Ribbon</p>
<p>常见的负载均衡：软件Nginx、LVS 硬件F5</p>
<h2 id="2、Ribbon初步配置"><a href="#2、Ribbon初步配置" class="headerlink" title="2、Ribbon初步配置"></a>2、Ribbon初步配置</h2><h3 id="1、修改consumer-80的配置"><a href="#1、修改consumer-80的配置" class="headerlink" title="1、修改consumer-80的配置"></a>1、修改consumer-80的配置</h3><ul>
<li><p>修改pom配置，增加相关引用</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--Ribbon相关引用，与eureka有关--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-eureka<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-ribbon<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-config<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>修改application.yml ,追加Eureka的注册服务地址</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">eureka:</span></span><br><span class="line"><span class="attr">  client:</span></span><br><span class="line"><span class="attr">    service-url:</span></span><br><span class="line"><span class="attr">      defaultZone:</span> <span class="string">eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka</span></span><br><span class="line"><span class="attr">    register-with-eureka:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>主启动类中增加注解@EnableEurekaClient，</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableEurekaClient</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DeptConsumer80App</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(DeptConsumer80App.class,args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>ConfigBean配置中增加@LoadBalance注解，开启客户端负载均衡</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ConfigBean</span> </span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 配置RestTemplate</span></span><br><span class="line"><span class="comment">     * 通过RestTemplate调用提供者服务 ，发送rest请求</span></span><br><span class="line"><span class="comment">     * 提供了多种访问http服务的方法，</span></span><br><span class="line"><span class="comment">     * 针对于访问rest服务&lt;strong&gt;客户端&lt;/strong&gt;的调用的模板类</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="meta">@LoadBalanced</span> <span class="comment">//ribbon实现的一套 ==客户端、负载均衡的工具</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span>  RestTemplate <span class="title">getRestTemplate</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> RestTemplate();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改客户端访问类80的controller，将地址改为微服务名称<strong>STUDY-SPRINGCLOUD-DEPT</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 注册再EurekaServer中的微服务名称</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> String REST_URL_PREFIX=<span class="string">"http://STUDY-SPRINGCLOUD-DEPT"</span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动</p>
<p>先启动Eureka集群，然后启动8001服务注册进eureka，再启动80客户端</p>
</li>
</ul>
<h2 id="3、Ribbon负载均衡"><a href="#3、Ribbon负载均衡" class="headerlink" title="3、Ribbon负载均衡"></a>3、Ribbon负载均衡</h2><h3 id="1、架构说明"><a href="#1、架构说明" class="headerlink" title="1、架构说明"></a>1、架构说明</h3><h3 id="2、新建8002、8003服务提供者"><a href="#2、新建8002、8003服务提供者" class="headerlink" title="2、新建8002、8003服务提供者"></a>2、新建8002、8003服务提供者</h3><p>复制8001的配置和类</p>
<p>yml配置中的实例名称application name不能改</p>
<h3 id="3、总结"><a href="#3、总结" class="headerlink" title="3、总结"></a>3、总结</h3><p>Ribbon其实就是一个软辅在均衡的客户端组件，他和其他所有需要请求的客户端结合使用，和Eureka结合只是其中的一个实例。默认采用轮询算法。</p>
<h2 id="4、Ribbon核心组件IRule"><a href="#4、Ribbon核心组件IRule" class="headerlink" title="4、Ribbon核心组件IRule"></a>4、Ribbon核心组件IRule</h2><p>IRule：根据特定算法中从服务列表中选取一个要访问的服务</p>
<h4 id="Ribbon采用的负载均衡算法："><a href="#Ribbon采用的负载均衡算法：" class="headerlink" title="Ribbon采用的负载均衡算法："></a>Ribbon采用的负载均衡算法：</h4><ul>
<li><p>com.netflix.loadbalancer.RoundRobinRule</p>
<p>轮询：默认</p>
</li>
<li><p>com.netflix.loadbalancer.RandomRule</p>
<p>随机</p>
</li>
<li><p>com.netflix.loadbalancer.AvailabilityFilteringRule</p>
<p>会先过滤掉由于多次访问故障而处于断路器跳闸状态的服务、还有并发的连接数量超过阈值的服务，然后对剩余的服务列表按照轮询策略进行访问</p>
</li>
<li><p>com.netflix.loadbalancer.WeightedResponseTimeRule</p>
<p>根据平均响应时间计算所有服务的权重，响应时间越快的服务权重越大，选中的概率越高。刚启动时如果统计信息不足，则上有RoundRobinRule策略，等统计信息足够，会切换到WeightedResponseTimeRule</p>
</li>
<li><p>com.netflix.loadbalancer.RetryRule</p>
<p>先按RoundRobinRule轮询算法获取服务，如果失败则在指定时间内进行重试</p>
</li>
<li><p>com.netflix.loadbalancer.BestAvailableRule</p>
<p>会先过滤掉由于多次访问故障而处于断路器跳闸状态的服务，然后选择一个并发量最小的服务</p>
</li>
<li><p>com.netflix.loadbalancer.ZoneAvoidanceRule</p>
<p>默认规则，复合判断Server所在区域的性能和Server的可用性选择服务</p>
</li>
</ul>
<h4 id="配置负载均衡算法"><a href="#配置负载均衡算法" class="headerlink" title="配置负载均衡算法"></a>配置负载均衡算法</h4><p>在ConfigBean中显示声明算法,增加bean</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Bean</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> IRule <span class="title">myRule</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="comment">//用我们选择的随机算法</span></span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> RandomRule();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5、Ribbon自定义"><a href="#5、Ribbon自定义" class="headerlink" title="5、Ribbon自定义"></a>5、Ribbon自定义</h2><h3 id="1、主启动类上添加注解-RibbonClient"><a href="#1、主启动类上添加注解-RibbonClient" class="headerlink" title="1、主启动类上添加注解@RibbonClient"></a>1、主启动类上添加注解@RibbonClient</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableEurekaClient</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 在启动该微服务式是能去加载我们定义的Ribbon配置类</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RibbonClient</span>(name=<span class="string">"STUDY-SPRINGCLOUD-DEPT"</span>,configuration = MySelfRule.class)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DeptConsumer80App</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(DeptConsumer80App.class,args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2、配置注意细节"><a href="#2、配置注意细节" class="headerlink" title="2、配置注意细节"></a>2、配置注意细节</h3><ul>
<li>自定义配置类不能放在@ComponentScan所扫描的当前包以及子包下，否则我们自定义的这个配置类就会被所有的Ribbon客户端锁共享，达不到特殊定制化的目的</li>
</ul>
<h3 id="3、自定义规则深度解析"><a href="#3、自定义规则深度解析" class="headerlink" title="3、自定义规则深度解析"></a>3、自定义规则深度解析</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">继承AbstractLoadBalancerRule</span></span><br><span class="line"><span class="comment">实现</span></span><br><span class="line"><span class="comment">**/</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyRandomRule</span> <span class="keyword">extends</span> <span class="title">AbstractLoadBalancerRule</span> </span>&#123;</span><br><span class="line">    <span class="comment">//实现代码</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


        </div>
        
    <div id='gitalk-container' class="comment link"
        data-ae='false'
        data-ci='eeec43124e53633945c0'
        data-cs='e2332cffb30ae24f185c1701286958cddd748ffb'
        data-r='kyralo.github.io'
        data-o='kyralo'
        data-a='kyralo'
        data-d='false'
    >查看评论</div>


    </div>
    
        <div class='side'>
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#三、Ribbon负载均衡"><span class="toc-number">1.</span> <span class="toc-text">三、Ribbon负载均衡</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1、概述"><span class="toc-number">1.1.</span> <span class="toc-text">1、概述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2、Ribbon初步配置"><span class="toc-number">1.2.</span> <span class="toc-text">2、Ribbon初步配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1、修改consumer-80的配置"><span class="toc-number">1.2.1.</span> <span class="toc-text">1、修改consumer-80的配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3、Ribbon负载均衡"><span class="toc-number">1.3.</span> <span class="toc-text">3、Ribbon负载均衡</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1、架构说明"><span class="toc-number">1.3.1.</span> <span class="toc-text">1、架构说明</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2、新建8002、8003服务提供者"><span class="toc-number">1.3.2.</span> <span class="toc-text">2、新建8002、8003服务提供者</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3、总结"><span class="toc-number">1.3.3.</span> <span class="toc-text">3、总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4、Ribbon核心组件IRule"><span class="toc-number">1.4.</span> <span class="toc-text">4、Ribbon核心组件IRule</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Ribbon采用的负载均衡算法："><span class="toc-number">1.4.0.1.</span> <span class="toc-text">Ribbon采用的负载均衡算法：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#配置负载均衡算法"><span class="toc-number">1.4.0.2.</span> <span class="toc-text">配置负载均衡算法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5、Ribbon自定义"><span class="toc-number">1.5.</span> <span class="toc-text">5、Ribbon自定义</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1、主启动类上添加注解-RibbonClient"><span class="toc-number">1.5.1.</span> <span class="toc-text">1、主启动类上添加注解@RibbonClient</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2、配置注意细节"><span class="toc-number">1.5.2.</span> <span class="toc-text">2、配置注意细节</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3、自定义规则深度解析"><span class="toc-number">1.5.3.</span> <span class="toc-text">3、自定义规则深度解析</span></a></li></ol></li></ol></li></ol>
        </div>
    
</div>


    </div>
</div>
</body>
<script src="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/kyralo/cdn/js/plugin.js"></script>
<script src="//cdn.jsdelivr.net/gh/kyralo/cdn/js/diaspora.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/kyralo/cdn/css/photoswipe.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/kyralo/cdn/css/default-skin.css">
<script src="//cdn.jsdelivr.net/gh/kyralo/cdn/js/photoswipe.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/kyralo/cdn/js/photoswipe-ui-default.min.js"></script>

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



<!-- Google Analytics -->
<script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-146789315-1', 'auto');
  ga('send', 'pageview');
</script>
<!-- End Google Analytics -->


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10/dist/APlayer.min.css">
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10/dist/APlayer.min.js"></script>
<style>
  .aplayer .aplayer-lrc {
    height: 35px;
  }
  .aplayer .aplayer-lrc p{
    font-size: 16px;
    font-weight: 700;
    line-height: 18px !important;
  }
  .aplayer .aplayer-lrc p.aplayer-lrc-current{
    color: #FF1493;
  }
  .aplayer.aplayer-narrow .aplayer-body{
    left: -66px !important;
  }
  .aplayer.aplayer-fixed .aplayer-lrc {
    display: none;
  }
  .aplayer .aplayer-lrc.aplayer-lrc-hide {
      display:none !important;
  }
  .aplayer.aplayer-fixed .lrc-show {
    display: block;
    background: rgba(255, 255, 255, 0.8);
  }
</style>
<div class="aplayer"

    data-id="2725346449"

    data-server="netease"

    data-type="playlist"

    data-fixed="true"

    data-autoplay="false"

    data-loop="all"

    data-order="random"

    data-preload="auto"

    data-volume="0.7"

    data-mutex="true"

</div>
<script src="https://cdn.jsdelivr.net/npm/meting@1.2/dist/Meting.min.js"></script>
<script>
  $(function(){
    $('body').on('click', '.aplayer', function(){
      if($('.aplayer-button').hasClass('aplayer-play')) {
        $('.aplayer-lrc').removeClass('lrc-show');
      } else {
        $('.aplayer-lrc').addClass('lrc-show');
      }
    })
  });
</script>
</html>
